package javase.swing;
import java.awt.event.*;
import javax.swing.*;

public class Memory extends JFrame implements ActionListener
{
	JProgressBar pgb_Used;
	JProgressBar pgb_Percent;
	JLabel lbl_Total;
	JLabel lbl_Percent;
	JPanel pnl_Main;
	Timer timer;
	public Memory()
	{
		super("�ڴ������");
		int TotalMemory;
		TotalMemory=(int)(Runtime.getRuntime().totalMemory()/8);
		pnl_Main=new JPanel();
		pnl_Main.setLayout(null);
		lbl_Total=new JLabel("�ڴ�ʹ�ã�");
		lbl_Total.setLocation(10,10);
		lbl_Total.setSize(200,20);
		lbl_Percent=new JLabel("�ٷֱȣ�");
		lbl_Percent.setLocation(10,70);
		lbl_Percent.setSize(200,20);
		pgb_Used=new JProgressBar(0,TotalMemory);
		pgb_Used.setLocation(10,40);
		pgb_Used.setSize(200,20);
		pgb_Percent=new JProgressBar(0,100);
		pgb_Percent.setLocation(10,100);
		pgb_Percent.setSize(200,20);
		pnl_Main.add(lbl_Total);
		pnl_Main.add(lbl_Percent);
		pnl_Main.add(pgb_Used);
		pnl_Main.add(pgb_Percent);
		timer=new Timer(1000,this);
		timer.start();
		this.addWindowListener(new WindowClose());
		this.setContentPane(pnl_Main);
		this.setResizable(false);
		this.setLocation(300,300);
		this.setSize(230,160);
		this.show();
	}
	public void actionPerformed(ActionEvent e)
	{
		int Total,Free,Used,Percent;
		Total=(int)(Runtime.getRuntime().totalMemory()/8);
		Free=(int)(Runtime.getRuntime().freeMemory()/8);
		Used=Total-Free;
		Percent=(int)(Used*100/Total);
		pgb_Used.setValue(Used);
		pgb_Percent.setValue(Percent);
		lbl_Total.setText("�ڴ�ʹ�ã�"+String.valueOf(Used)+" KB / "+String.valueOf(Total)+" KB");
		lbl_Percent.setText("�ٷֱȣ�"+String.valueOf(Percent)+" %");
	}
	class WindowClose extends WindowAdapter
	{
		public void windowClosing(WindowEvent e)
		{
			System.exit(0);
		}
	}
	public static void main(String []args)
	{
		new Memory();
	}
}